package club.jdiy.core.convert;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

class LongConverter extends NumberConverter<Long> {
    public LongConverter(Long source) {
        super(source);
    }

    @Override
    public Boolean getBoolean() {
        return source != 0;
    }

    @Override
    public Byte getByte() {
        if (source > Byte.MAX_VALUE || source < Byte.MIN_VALUE) {
            throw __throw(Byte.class);
        } else {
            return source.byteValue();
        }
    }


    @Override
    public Short getShort() {
        if (source > Short.MAX_VALUE || source < Short.MIN_VALUE) {
            throw __throw(Short.class);
        } else {
            return source.shortValue();
        }
    }

    @Override
    public Integer getInteger() {
        if (source > Integer.MAX_VALUE || source < Integer.MIN_VALUE) {
            throw __throw(Integer.class);
        } else {
            return source.intValue();
        }
    }

    @Override
    public Long getLong() {
        return getSource();
    }

    @Override
    public Date getDate() {
        return new Date(source);
    }


    @Override
    public LocalDateTime getLocalDateTime() {
        return Instant.ofEpochMilli(source).atOffset(ZoneOffset.ofHours(8)).toLocalDateTime();
    }

    @Override
    public LocalDate getLocalDate() {
        return Instant.ofEpochMilli(source).atOffset(ZoneOffset.ofHours(8)).toLocalDate();
    }

    @Override
    public BigDecimal getBigDecimal() {
        return BigDecimal.valueOf(source);
    }

    @Override
    public BigInteger getBigInteger() {
        return BigInteger.valueOf(source);
    }
}
